<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js"></script>
</head>
<body>
    <div id="app">

        <button @click="add">尾部增加</button>
        <button @click="unshift">头部增加</button>
        <!-- vue中利用v-for来遍历数组 是将遍历的联系写在 遍历出来的标签上 并不是写在父级上面 -->
        <ul>
            <li v-for="item in persons" :key="item.id">
                {{item.name}}---{{item.age}}
            </li>
        </ul>
    </div>
    <script>
        const vm =new Vue({
            el:"#app",
            data(){
                return {
                    persons:[
                        { id: "001", name: "laowang", age: 19 },
                        { id: "002", name: "xiaowang", age: 29 },
                        { id: "003", name: "zhongwang", age: 9 },
                    ]
                }
            },
            methods:{
                add(){
                    this.persons = [...this.persons,{ id: "004", name: "laowang", age: 19 }]
                },
                unshift(){
                    this.persons = [{ id: "004", name: "laowang", age: 19 },...this.persons]
                }

            }

        })
    </script>
</body>
</html>